import {Component, OnInit, Output} from "@angular/core";
import {Hero} from "../../models/hero";
import {HeroesService} from "../../services/heroes.service";

@Component({
  selector: 'hero-list',
  templateUrl: './hero-list.component.html',
  styleUrls: ['./hero-list.component.css']
})
export class HeroListComponent implements OnInit {
  private heroes: Hero[]

  @Output()
  selected: Hero


  constructor(private service: HeroesService) {
    // this.service.getHero(1).subscribe(hero =>
    //   console.log(hero)
    // )

    // this.service.getHero(21).subscribe(hero =>
    //   console.log(hero)
    // )
  }

  ngOnInit() {
    this.service.getHeroes().subscribe((heroes)=> {
      this.heroes = heroes
    })
  }

  selectHero(hero: Hero) {
    this.selected = hero
  }

  isSelected(hero: Hero) {
    return hero === this.selected
  }
}
